package cn.com.b2office.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.b2office.dao.PaymentModeDao;
import cn.com.b2office.domain.PaymentMode;

public class PaymentModeDaoHibernateImpl extends HibernateDaoSupport implements
		PaymentModeDao {

	@SuppressWarnings("unchecked")
	public List<PaymentMode> findAllPaymentModes() {
		List<PaymentMode> list = null;
		Session s = getSession();
		try {
			Query query = s.createQuery("from PaymentMode");
			query.setCacheable(true);
			list = query.list();
		} catch (RuntimeException e) {
			throw e;
		} finally {
			releaseSession(s);
		}
		return list;
	}

	public PaymentMode getPaymentMode(int id) {
		return (PaymentMode) getHibernateTemplate().get(PaymentMode.class, id);
	}

	public PaymentMode getDefaultPaymentMode() {
		return findAllPaymentModes().get(0);
	}

}
